package com.libin8002.service.impl;

import com.libin.entities.CommonResult;
import com.libin.entities.Payment;
import com.libin8002.dao.PaymentMapper;
import com.libin8002.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class PaymentServiceImpl implements PaymentService {
    @Autowired
    PaymentMapper paymentMapper;

    @Value("${server.port}")
    private String port;//端口号

    /**
     * 查询指定订单编号
     * @param id
     * @return
     */
    public CommonResult select(Integer id){
        Payment select = paymentMapper.select(id);
        Map map=new HashMap();
        if(select!=null){
            map.put("code",200);
            map.put("msg","成功");
            map.put("data",select);
            return new CommonResult(200,"成功port"+port,select);
        }else{
            map.put("code",404);
            map.put("msg","没有该资源");
            map.put("data",null);
            return new CommonResult(404,"没有该资源");
        }
    }

    /**
     * 增加订单编号
     * @param payment
     * @return
     */
    @Override
    public CommonResult add(Payment payment) {
        if(payment==null){
            return new CommonResult(401,"参数为空");
        }else{
            Integer insert = paymentMapper.insert(payment);
            if(insert>0){
                return new CommonResult(200,"成功port"+port,insert);
            }else{
                return new CommonResult(500,"失败");
            }
        }
    }
}
